import request from '../../../util/request';
import {userServer} from '../../../config/config';

/**
 * 存储角色
 */
function saveRole({role, description}) {
	return request(userServer('/api/role/saveRole'), {
		data: {role, description}
	});
}

/**
 * 移除角色
 */
function removeRole({roleId}) {
	return request(userServer('/api/role/removeRole'), {
		data: {roleId}
	});
}

/**
 * 更新角色
 */
function updateRole({roleId, role, description}) {
	return request(userServer('/api/role/updateRole'), {
		data: {roleId, role, description}
	});
}

/**
 * 同步权限
 */
function synPermission({roleId, permissionIds}) {
	return request(userServer('/api/role/synPermission'), {
		data: {roleId, permissionIds}
	});
}

/**
 * 添加角色权限
 */
function addPermission({roleId, permissionIds}) {
	return request(userServer('/api/role/addPermission'), {
		data: {roleId, permissionIds}
	});
}

/**
 * 移除角色权限
 */
function removePermission({roleId, permissionIds}) {
	return request(userServer('/api/role/removePermission'), {
		data: {roleId, permissionIds}
	});
}

/**
 * 通过用户id获取角色列表
 */
function listRoleByUserId({userId}) {
	return request(userServer('/api/role/listRoleByUserId'), {
		data: {userId}
	});
}

/**
 * 分页获取角色
 */
function pageRole({pageNum, pageSize}) {
	return request(userServer('/api/role/pageRole'), {
		data: {pageNum, pageSize}
	});
}

export {
	saveRole,
	removeRole,
	updateRole,
	synPermission,
	addPermission,
	removePermission,
	listRoleByUserId,
	pageRole,
}
